package com.ht.demo.service.convert.system;

import com.ht.demo.common.appexception.AppErrorCodeEnum;
import com.ht.demo.common.appexception.AppException;
import com.ht.demo.common.pojo.bo.system.SysDictDataBO;
import com.ht.demo.dao.domain.system.SysDictDataDO;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 类SysDictDataBeanUtil.java的实现描述：字典数据表工具类
 * 
 * @Author hdengxian
 * @Date 2023年05月24日
 */
public class SysDictDataBeanUtil {

    private SysDictDataBeanUtil(){
    }

    public static SysDictDataDO sysDictDataBOToDO(SysDictDataBO srcObj) {
        if (srcObj == null) {
            return null;
        }
        SysDictDataDO targetObj = new SysDictDataDO();
        /**字典编码**/
        targetObj.setId(srcObj.getSysDictDataId());
        /**字典类型**/
        targetObj.setDictType(srcObj.getDictType());
        /**字典标签**/
        targetObj.setDictLabel(srcObj.getDictLabel());
        /**字典键值**/
        targetObj.setDictValue(srcObj.getDictValue());
        /**字典排序**/
        targetObj.setDictSort(srcObj.getDictSort());
        /**样式属性（其他样式扩展）**/
        targetObj.setCssClass(srcObj.getCssClass());
        /**表格回显样式**/
        targetObj.setListClass(srcObj.getListClass());
        /**是否默认（Y是 N否）**/
        targetObj.setIsDefault(srcObj.getIsDefault());
        /**状态（0正常 1停用）**/
        targetObj.setStatus(srcObj.getStatus());
        /**创建者**/
        targetObj.setCreateBy(srcObj.getCreateBy());
        /**创建时间**/
        targetObj.setCreateTime(srcObj.getCreateTime());
        /**更新者**/
        targetObj.setUpdateBy(srcObj.getUpdateBy());
        /**更新时间**/
        targetObj.setUpdateTime(srcObj.getUpdateTime());
        /**备注**/
        targetObj.setRemark(srcObj.getRemark());

        return targetObj;
    }

    public static SysDictDataBO sysDictDataDOToBO(SysDictDataDO srcObj) {
        if (srcObj == null) {
            return null;
        }
        SysDictDataBO targetObj = new SysDictDataBO();
        /**字典编码**/
        targetObj.setSysDictDataId(srcObj.getId());
        /**字典类型**/
        targetObj.setDictType(srcObj.getDictType());
        /**字典标签**/
        targetObj.setDictLabel(srcObj.getDictLabel());
        /**字典键值**/
        targetObj.setDictValue(srcObj.getDictValue());
        /**字典排序**/
        targetObj.setDictSort(srcObj.getDictSort());
        /**样式属性（其他样式扩展）**/
        targetObj.setCssClass(srcObj.getCssClass());
        /**表格回显样式**/
        targetObj.setListClass(srcObj.getListClass());
        /**是否默认（Y是 N否）**/
        targetObj.setIsDefault(srcObj.getIsDefault());
        /**状态（0正常 1停用）**/
        targetObj.setStatus(srcObj.getStatus());
        /**创建者**/
        targetObj.setCreateBy(srcObj.getCreateBy());
        /**创建时间**/
        targetObj.setCreateTime(srcObj.getCreateTime());
        /**更新者**/
        targetObj.setUpdateBy(srcObj.getUpdateBy());
        /**更新时间**/
        targetObj.setUpdateTime(srcObj.getUpdateTime());
        /**备注**/
        targetObj.setRemark(srcObj.getRemark());

        targetObj.setLabel(srcObj.getDictLabel());
        targetObj.setValue(srcObj.getDictValue());
        return targetObj;
    }

    public static List<SysDictDataBO> doList2BOList(List<SysDictDataDO> doList) {
        List<SysDictDataBO> boList = new ArrayList<>();
        if (CollectionUtils.isEmpty(doList)) return boList;

        doList.stream().forEach(d -> boList.add(SysDictDataBeanUtil.sysDictDataDOToBO(d)));
        return boList;
    }

    public static List<SysDictDataDO> boList2DOList(List<SysDictDataBO> boList) {
        List<SysDictDataDO> doList = new ArrayList<>();
        if (CollectionUtils.isEmpty(boList)) return doList;

        boList.stream().forEach(b -> doList.add(SysDictDataBeanUtil.sysDictDataBOToDO(b)));
        return doList;
    }

    public static void insertCheckParams(SysDictDataBO dictDataBO) throws AppException {
        if (dictDataBO == null) {
            throw new AppException(AppErrorCodeEnum.PARAMETER_ERROR);
        }
        if (StringUtils.isBlank(dictDataBO.getDictType())) {
            throw new AppException(AppErrorCodeEnum.PARAMETER_ERROR);
        }
        if (StringUtils.isBlank(dictDataBO.getDictLabel())) {
            throw new AppException(AppErrorCodeEnum.PARAMETER_ERROR);
        }
        if (StringUtils.isBlank(dictDataBO.getDictValue())) {
            throw new AppException(AppErrorCodeEnum.PARAMETER_ERROR);
        }
        if (StringUtils.isBlank(dictDataBO.getIsDefault())) {
            dictDataBO.setIsDefault("N");
        }
        if (StringUtils.isBlank(dictDataBO.getStatus())) {
            dictDataBO.setStatus("0");
        }
    }
}